package com.ch;

import com.ch.exception.myexception;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class excetionGloble {
    Logger logger=Logger.getLogger(excetionGloble.class);
    @ExceptionHandler(RuntimeException.class)
    public Result runTimeException(RuntimeException runtimeException ){
        logger.info(runtimeException.getMessage());
        System.out.println("运行时错误");
        return Result.error(500,"运行时异常");
    }
    @ExceptionHandler(Exception.class)
    public Result allExeception(Exception e){
        logger.info(e.getMessage());
        System.out.println("所有的异常处理");
        return Result.error(500,"所有的异常处理");
    }
    @ExceptionHandler(myexception.class)
    public Result myException(myexception myexception)
    {
        logger.info(myexception.getMessage());
        logger.info(myexception.getCode());
        System.out.println("自定义异常");
        return Result.error(501,"这是我自定义的错误");
    }
}
